package com.tracesystem.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tracesystem.commons.Result;
import com.tracesystem.controller.Info.AllStatePageInfo;
import com.tracesystem.controller.form.*;
import com.tracesystem.dao.IssueStateDao;
import com.tracesystem.model.IssueState;
import com.tracesystem.service.IssueStateService;
import com.tracesystem.util.WoniuCopyUtil;
import com.tracesystem.util.exception.IssueStateException;
import com.tracesystem.util.exception.code.IssueStateExceptionCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Kevin Martin
 * @since 2022-03-23
 */
@RestController
@RequestMapping("/issueState")
@Api(tags = "缺陷状态操作相关接口")
public class IssueStateController {

    /**
     * 缺陷分类业务层对象
     */
    @Resource
    private IssueStateService issueStateService;

    /**
     * 缺陷分类实现层对象
     */
    @Resource
    private IssueStateDao issueStateDao;

    /**
     * 添加缺陷分类项
     * @param addStateForm
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @ApiOperation("新增缺陷状态")
    @PostMapping("/addState")
    public Result<?> addState(@Valid @RequestBody AddStateForm addStateForm){
        return issueStateService.insertState(addStateForm);
    }

    /**
     * 删除缺陷状态项
     * @param removeStateForm
     * @return
     */
    @ApiOperation("删除缺陷状态")
    @PostMapping("/removeState")
    public Result<?> removeState(@RequestBody RemoveStateForm removeStateForm){
        return issueStateService.delectState(removeStateForm);
    }

    /**
     * 批量删除缺陷状态项
     * @param removeStateListForm
     * @return
     */
    @ApiOperation("批量删除缺陷状态")
    @PostMapping("/removeStateList")
    public Result<?> removeStateList(@RequestBody RemoveStateListForm removeStateListForm){
        return issueStateService.delectStateList(removeStateListForm);
    }

    /**
     * 修改缺陷分类
     * @param renewalStateDescForm
     * @return
     */
    @ApiOperation("修改缺陷分类")
    @PostMapping("/renewalStateDesc")
    public Result<?> renewalStateDesc(@RequestBody RenewalStateDescForm renewalStateDescForm){
        return issueStateService.updateStateDesc(renewalStateDescForm);
    }

    /**
     * 修改缺陷分类项
     * @param renewalStateModuleStateForm
     * @return
     */
    @ApiOperation("修改缺陷状态：禁用/启用")
    @PostMapping("/renewalStateModuleState")
    public Result<?> renewalStateModuleState(@RequestBody RenewalStateModuleStateForm renewalStateModuleStateForm){
        return issueStateService.updateModuleState(renewalStateModuleStateForm);
    }

    /**
     * 模糊查询缺陷分类
     * @param likeStateListForm
     * @return
     */
    @ApiOperation("模糊查询缺陷分类")
    @PostMapping("/likeStateList")
    public Result<AllStatePageInfo> likeStateList(@RequestBody LikeStateListForm likeStateListForm){
        return issueStateService.findPageStateListByStateDesc(likeStateListForm);
    }

    /**
     * 查询所有缺陷分类
     * @param findAllStateListForm
     * @return
     */
    @ApiOperation("查询所有缺陷分类")
    @PostMapping("/findAllStateList")
    public Result<AllStatePageInfo> findAllStateList(@RequestBody FindAllStateListForm findAllStateListForm){
        return issueStateService.getAllStateList(findAllStateListForm);
    }


}

